home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / gs24src.zip / ZPATH2.C < prev    next >
C/C++ Source or Header  |  1991-12-04  |  5KB  |  178 lines

  1. /* Copyright (C) 1989, 1990, 1991 Aladdin Enterprises.  All rights reserved.
  2.    Distributed by Free Software Foundation, Inc.
  3.  
  4. This file is part of Ghostscript.
  5.  
  6. Ghostscript is distributed in the hope that it will be useful, but
  7. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. to anyone for the consequences of using it or for whether it serves any
  9. particular purpose or works at all, unless he says so in writing.  Refer
  10. to the Ghostscript General Public License for full details.
  11.  
  12. Everyone is granted permission to copy, modify and redistribute
  13. Ghostscript, but only under the conditions described in the Ghostscript
  14. General Public License.  A copy of this license is supposed to have been
  15. given to you along with Ghostscript so you can know your rights and
  16. responsibilities.  It should be in a file named COPYING.  Among other
  17. things, the copyright notice and this notice must be preserved on all
  18. copies.  */
  19.  
  20. /* zpath2.c */
  21. /* Non-constructor path operators for GhostScript */
  22. #include "ghost.h"
  23. #include "oper.h"
  24. #include "errors.h"
  25. #include "alloc.h"
  26. #include "estack.h"    /* for pathforall */
  27. #include "gspath.h"
  28. #include "state.h"
  29. #include "store.h"
  30.  
  31. /* flattenpath */
  32. int
  33. zflattenpath(register os_ptr op)
  34. {    return gs_flattenpath(igs);
  35. }
  36.  
  37. /* reversepath */
  38. int
  39. zreversepath(register os_ptr op)
  40. {    return gs_reversepath(igs);
  41. }
  42.  
  43. /* strokepath */
  44. int
  45. zstrokepath(register os_ptr op)
  46. {    return gs_strokepath(igs);
  47. }
  48.  
  49. /* clippath */
  50. int
  51. zclippath(register os_ptr op)
  52. {    return gs_clippath(igs);
  53. }
  54.  
  55. /* pathbbox */
  56. int
  57. zpathbbox(register os_ptr op)
  58. {    gs_rect box;
  59.     int code = gs_pathbbox(igs, &box);
  60.     if ( code < 0 ) return code;
  61.     push(4);
  62.     make_real(op - 3, box.p.x);
  63.     make_real(op - 2, box.p.y);
  64.     make_real(op - 1, box.q.x);
  65.     make_real(op, box.q.y);
  66.     return 0;
  67. }
  68.  
  69. /* pathforall */
  70. private int path_continue(P1(os_ptr));
  71. private int i_path_continue;
  72. int
  73. zpathforall(register os_ptr op)
  74. {    gs_path_enum *penum;
  75.     check_op(4);
  76.     check_estack(8);
  77.     if ( (penum = (gs_path_enum *)alloc(1, gs_path_enum_sizeof, "pathforall")) == 0 )
  78.       return e_VMerror;
  79.     gs_path_enum_init(penum, igs);
  80.     /* Push a mark, the four procedures, and a pseudo-integer */
  81.     /* in which value.bytes points to the path enumerator, */
  82.     /* and then call the continuation procedure. */
  83.     mark_estack(es_for);    /* iterator */
  84.     *++esp = op[-3];    /* moveto proc */
  85.     *++esp = op[-2];    /* lineto proc */
  86.     *++esp = op[-1];    /* curveto proc */
  87.     *++esp = *op;        /* closepath proc */
  88.     ++esp;
  89.     make_tv(esp, t_integer, bytes, (byte *)penum);
  90.     pop(4);  op -= 4;
  91.     return path_continue(op);
  92. }
  93. /* Continuation procedure for pathforall */
  94. private int pf_push(P3(gs_point *, int, os_ptr));
  95. private int
  96. path_continue(register os_ptr op)
  97. {    gs_path_enum *penum = (gs_path_enum *)esp->value.bytes;
  98.     gs_point ppts[3];
  99.     int code;
  100.     code = gs_path_enum_next(penum, ppts);
  101.     switch ( code )
  102.       {
  103.     case 0:            /* all done */
  104.         { alloc_free((char *)penum, 1, gs_path_enum_sizeof, "pathforall");
  105.           esp -= 6;
  106.           return o_pop_estack;
  107.         }
  108.     default:        /* error */
  109.         return code;
  110.     case gs_pe_moveto:
  111.         esp[2] = esp[-4];            /* moveto proc */
  112.         code = pf_push(ppts, 1, op);
  113.         break;
  114.     case gs_pe_lineto:
  115.         esp[2] = esp[-3];            /* lineto proc */
  116.         code = pf_push(ppts, 1, op);
  117.         break;
  118.     case gs_pe_curveto:
  119.         esp[2] = esp[-2];            /* curveto proc */
  120.         code = pf_push(ppts, 3, op);
  121.         break;
  122.     case gs_pe_closepath:
  123.         esp[2] = esp[-1];            /* closepath proc */
  124.         code = 0;
  125.         break;
  126.       }
  127.     if ( code < 0 ) return code;    /* ostack overflow in pf_push */
  128.     push_op_estack(path_continue, i_path_continue);
  129.     ++esp;        /* include pushed procedure */
  130.     return o_push_estack;
  131. }
  132. /* Internal procedure to push one or more points */
  133. private int
  134. pf_push(gs_point *ppts, int n, os_ptr op)
  135. {    while ( n-- )
  136.       { push(2);
  137.         make_real(op - 1, ppts->x);
  138.         make_real(op, ppts->y);
  139.         ppts++;
  140.       }
  141.     return 0;
  142. }
  143.  
  144. /* initclip */
  145. int
  146. zinitclip(register os_ptr op)
  147. {    return gs_initclip(igs);
  148. }
  149.  
  150. /* clip */
  151. int
  152. zclip(register os_ptr op)
  153. {    return gs_clip(igs);
  154. }
  155.  
  156. /* eoclip */
  157. int
  158. zeoclip(register os_ptr op)
  159. {    return gs_eoclip(igs);
  160. }
  161.  
  162. /* ------ Initialization procedure ------ */
  163.  
  164. op_def zpath2_op_defs[] = {
  165.     {"0clip", zclip},
  166.     {"0clippath", zclippath},
  167.     {"0eoclip", zeoclip},
  168.     {"0flattenpath", zflattenpath},
  169.     {"0initclip", zinitclip},
  170.     {"0pathbbox", zpathbbox},
  171.     {"4pathforall", zpathforall},
  172.     {"0reversepath", zreversepath},
  173.     {"0strokepath", zstrokepath},
  174.         /* Internal operators */
  175.     {"0%path_continue", path_continue, &i_path_continue},
  176.     op_def_end(0)
  177. };
  178.